function [ Z,F ] = brute_force_Z( w, x, S,seg)
    Z = 0;
    for label=1:2^size(x,2)
        y = dec2bin(label-1,size(x,2));

        F = zeros(4*size(seg,1),1);
        usedsegs = zeros(size(seg,1),1);
        for i=2:min(5,size(x,2))
            [F,usedsegs] = parseword( x, y, i, S, F, usedsegs );
        end
        
        sum = 0;
        for j = 1:size(w,1)
            sum = sum + w(j)*F(j);
        end
        Z = Z + exp(sum);
    end
end
